export default {
  getWGS84Distance
}

/**
 * @description EPSG:4326 获取两点之间的经纬度
 * @param {Array} prev 起点经纬度 ["116.39786526", "39.92421163"]
 * @param {Array} next 重点经纬度 ["116.39593675", "39.92629634"]
 * @returns {Number}
 */
export const getWGS84Distance = (prev, next) => {
  if (!prev || !next) { return 0 }
  // EARTH_RADIUS
  const EARTH_RADIUS = 6378.137
  const [startLng, startLat] = prev
  const [endLng, endLat] = next
  const radLat1 = (startLat * Math.PI) / 180.0
  const radLat2 = (endLat * Math.PI) / 180.0
  const a = radLat1 - radLat2
  const b = (startLng * Math.PI) / 180.0 - (endLng * Math.PI) / 180.0
  const v = Math.pow(Math.sin(a / 2), 2)
    + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)
  let dis = 2 * Math.asin(Math.sqrt(v))
  dis = parseFloat((dis * EARTH_RADIUS * 1000).toFixed(1))
  // 调用 return的距离单位为m
  return dis
}